package cn.zakrov.sbs008.controller;

import cn.zakrov.sbs008.entity.JsonResult;
import cn.zakrov.sbs008.exception.BusinessErrorException;
import cn.zakrov.sbs008.exception.BusinessMsgEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exception")
public class ExceptionController {
    private static final Logger logger = LoggerFactory.getLogger(ExceptionController.class);

    @GetMapping("/npe")
    public JsonResult testNullPointerException() {
        String str = null;
        str.length();
        return new JsonResult();
    }

    @GetMapping("/be")
    public JsonResult testBusinessException() {
        try {
            int i = 1 / 0;
        } catch (Exception e) {
            throw new BusinessErrorException(BusinessMsgEnum.UNEXPECTED_EXCEPTION);
        }
        return new JsonResult();
    }

    @GetMapping("/msrqe")
    public JsonResult test(@RequestParam("name") String name, @RequestParam("pass") String pass) {
        logger.info(name + ", " + pass);
        return new JsonResult();
    }
}
